package com.agrm.rabc.service.impl;

import com.agrm.model.rabc.dto.Resource;
import com.agrm.model.rabc.pojo.ResourceSearchBean;
import com.agrm.rabc.mapper.ResourceDao;
import com.agrm.rabc.service.ResourceService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


@CacheConfig(cacheNames = "c.s.r.s.impl.ResourceServiceImpl")
@Service
public class ResourceServiceImpl implements ResourceService {
    private ResourceDao resourceDao;

    @Autowired
    public void setResourceDao(ResourceDao resourceDao) {
        this.resourceDao = resourceDao;
    }

    @Override
    public Page<Resource> findAll(ResourceSearchBean rsb, Page<Resource> page) {
        return resourceDao.findAll(rsb, page);
    }

    @Cacheable(key = "#p0")
    @Override
    public Resource findById(Integer id) {
        return resourceDao.selectById(id);
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean save(Resource resource) {
        return resourceDao.insert(resource) > 0;
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean update(Resource resource) {
        return resourceDao.updateById(resource) > 0;
    }

    @CacheEvict(allEntries = true)
    @Override
    public int deleteByIds(List<Integer> ids) {
        return resourceDao.deleteByIds(ids);
    }
}
